import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ResponseInterceptor } from './common/appResponseIntercepty';
import { AppExceptionFilter } from './common/appExceptionFilter';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule } from '@nestjs/swagger';
import { swaggerConfig } from './config';

async function bootstrap() {

  const app = await NestFactory.create(AppModule);

  app.setGlobalPrefix('api');
  app.enableCors();
  app.useGlobalInterceptors(new ResponseInterceptor());
  app.useGlobalFilters(new AppExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());

  // 设置 Swagger 文档
  const document = SwaggerModule.createDocument(app, swaggerConfig);
  SwaggerModule.setup('api-docs', app, document);

  await app.listen(process.env.PORT);

  console.log(`🚀 Application is running on: http://localhost:${process.env.PORT}/api`);
  console.log(`📝 API Documentation: http://localhost:${process.env.PORT}/api-docs`);
  console.log(`🔥 Environment: ${process.env.NODE_ENV}`);
}
bootstrap();
